package com.cndatacom.teleweb.dao.impl;

import com.cndatacom.teleweb.common.PaginationModel;
import com.cndatacom.teleweb.common.PaginationSupport;
import com.cndatacom.teleweb.dao.IQuestionAnswerDao;
import com.cndatacom.teleweb.model.QuestionAnswer;

public class QuestionAnswerDao extends PaginationSupport implements
		IQuestionAnswerDao {

	public QuestionAnswer addQuestionAnswer(QuestionAnswer questionAnswer) {
		getHibernateTemplate().save(questionAnswer);
		return questionAnswer;
	}

	public boolean delQuestionAnswer(QuestionAnswer questionAnswer) {
		getHibernateTemplate().delete(questionAnswer);
		return true;
	}

	public PaginationModel getAllQuestionAnswer(int offset, int pageSize) {
		return searchPaginated("select qa from com.cndatacom.teleweb.model.QuestionAnswer qa order by qa.publishDate desc", offset, pageSize);
	}

	public PaginationModel getPendingQuestionAnswer(int offset, int pageSize) {
		return searchPaginated("select qa from com.cndatacom.teleweb.model.QuestionAnswer qa where status = 0 order by qa.publishDate desc", offset, pageSize);
	}
	
	public PaginationModel getPublishQuestionAnswer(int offset, int pageSize) {
		return searchPaginated("select qa from com.cndatacom.teleweb.model.QuestionAnswer qa where status = 1 and publishDate <= current_timestamp() order by qa.publishDate desc", offset, pageSize);
	}
	
	public QuestionAnswer getQuestionAnswerById(int questionId) {
		return (QuestionAnswer)getHibernateTemplate().get(QuestionAnswer.class, questionId);
	}

	public QuestionAnswer updateQuestionAnswer(QuestionAnswer questionAnswer) {
		getHibernateTemplate().update(questionAnswer);
		return questionAnswer;
	}

}
